<style>
body {
	text-align:center;
	margin:0px;
}

#device_edit_content {
	position: absolute;
	z-index: auto;
	height: auto;
	width: 1000px;
	left:0px;
	top:80px;

}
#device_edit_menu {
	width:200px;
	padding-left:20px;
	height:auto;
	text-align:left;	
}
#device_edit_top {
	width:500px;
	height:auto;
	margin-top:10px;
	padding-left:250px;

}
#device_edit_content #device_edit_top table {
	font-family: "ＭＳ Ｐゴシック", "ＭＳ ゴシック", "ＭＳ Ｐ明朝", "ＭＳ 明朝", "MS UI Gothic";
	font-size: 14px;
	text-align: center;
}
#device_edit_content #indexform table tr td {
	font-family: "ＭＳ Ｐゴシック", "ＭＳ ゴシック", "ＭＳ Ｐ明朝", "ＭＳ 明朝", "MS UI Gothic";
	font-size: 14px;
}
</style>
	<!--{include /service/service_head}-->
	<div id="device_edit_content">
	<div id="device_edit_menu">
		<ul>
			${servicemanage_backend($oauthMap)}
		</ul>
	</div>
	<form action="/service/deviceManageEdit.php" id="indexform" method="post">
		
	
	<div id="device_edit_top">
		<table border="1" cellpadding="0" cellspacing="0" width="500">
		<tr>
			<td align="right">
				設備名：
			</td>
			<td align="left">
				<input type="hidden" value="{$device['id']}" name="device_id" />
				<input type="text" value="{$device['device_name']}" name="device_name" />
			</td>
		</tr>
		<!--{if $device['id'] > 0}-->
		<tr>
			<td align="right">
				設備利用コース名：
			</td>
			<td id="addDelete" align="left">
				<!--{loop DeviceUse::GetServicesById($device['id']) $index1 $one1}-->
				<a class="delete" deviceId="{$device['id']}" serviceId="{$one1['id']}"></a><span>{$one1['service_name']}(level:{$one1['skill_level']})</span>,
				<!--{/loop}-->
				
			</td>
		</tr>
		<tr>
			<td align="right">利用コース登録：</td>
			<td align="left">
				<select name="service_id" class="f-city" style="width:200">
					<option value="0">選択してください</option>
					${Utility::Option(Utility::OptionArray($serviceList, 'id', 'service_name'), 0)}
				</select>
				
				level:<select name="skill_level" class="f-city">
					<option value="1">1</option>
					<option value="2">2</option>
					<option value="3">3</option>
				</select>
				<input type="button" value="登録" id="addService" />
			</td>
		</tr>
		<!--{/if}-->
		
		<tr>
			<td align="right">
				設備在庫数：</td>
			<td align="left">
				<input type="text" value="{$device['device_count']}" name="device_count" />
			</td>
		</tr>
		<tr>
			<td align="right">
				所属店舗：
			</td>
			<td align="left">
				<select name="shop_id" class="f-city">
					<option value="0">選択してください</option>
					${Utility::Option(Utility::OptionArray($shopList, 'id', 'shop_name'), $device['shop_id'])}
				</select>
			</td>
		</tr>
		<tr>
			<td>
			<!--{if $oauthMap[43] != null}--><!--{/if}-->
			</td>
		</tr>
		<tr>
		  <td><input type="submit" value="確認する" /></td>
		  </tr>
		
		</table>
	<div>
	</form>
	</div>
		<a href="{$_SERVER['HTTP_REFERER']}">戻る</a>
	</div>
	</div>
</body>
</html>
<script type="text/javascript"> 
jQuery(function(){
	$("a[class='delete']").bind('click', function(){
		var data = "action=del&serviceId=" + $(this).attr("serviceId") + "&deviceId=" + $(this).attr('deviceId');
		
		var This = this;
		$.get("{$webRoot}/service/deviceSkillEdit.php", data, function(data){
			if( data['error'] == 0 ){
				$(This).next().remove();
				$(This).unbind('click');
				$(This).remove();
			}
			
		}, "json");
	});

	$("#addService").bind('click', function(){
		var deviceId = $("input[name='device_id']").val();
		var serviceId = $("select[name='service_id']").val();
		if( serviceId < 1 ){
			return ;
		}
		var data = "action=add&serviceId=" + serviceId + "&deviceId=" + deviceId;
		data = data + "&skillLevel=" + $("select[name='skill_level']").val();
		$.get("{$webRoot}/service/deviceSkillEdit.php", data, function(data){
			if( data['error'] == 0 ){
				$("#addDelete").append('<a class="delete" deviceId="' + deviceId + '" serviceId="' + serviceId + '"></a><span>' + data.data + '</span>');
				$("a[class='delete']").last().bind('click', function(){
					var data = "action=del&serviceId=" + $(this).attr("serviceId") + "&deviceId=" + $(this).attr('deviceId');
					var This = this;
					$.get("{$webRoot}/service/deviceSkillEdit.php", data, function(data){
						if( data['error'] == 0 ){
							$(This).next().remove();
							$(This).unbind('click');
							$(This).remove();
						}
						
					}, "json");
				})
			}
		}, "json");
	});

	$("select[name='shop_id']").bind("change", function(){
		if( $(this).val() < 1 ){
			return ;
		}
		$.get("{$webRoot}/ajax/GetServiceList.php", "shopId=" + $(this).val(), function(data){
			var options = '<option value="0">選択してください</option>';
			for(var index in data.data){
				if( !index ){
					continue;
				}
				options = options + '<option value="' + index + '">' + data.data[index].service_name + '</option>';
			}
			$("select[name='service_id']").html(options);
		}, "json");
		
	});
})
</script> 
</html> 